﻿Imports DAO
Imports DTO
Public Class DoanhThuTrongNgayBUS
    Public Function DOANHTHU(ByVal ngaykham As Date) As Integer
        'bien thanh vien
        Dim TongTienKham As Long
        Dim TongTienThuoc As Long
        Dim tienkhambenhnhan As Long
        Dim _TongTien As Long
        Dim query As String
        Dim DT_THUOC As New DataTable()
        'ham`
        Dim THAMSO_DAO As New ThamSoDAO()
        Dim DoanhThuTrongNgay_DAO As New DoanhThuTrongNgayDAO()
        Dim DTP As New DataProvider()

        'lay ra so benh nhan * tien kham
        tienkhambenhnhan = THAMSO_DAO.tienkhambenhnhan()
        Dim SoBenhNhanTrongNgay = DoanhThuTrongNgay_DAO.SBNTrongNgay(ngaykham)
        TongTienKham = SoBenhNhanTrongNgay * tienkhambenhnhan
        '
        'lay ra ma thuoc + so luong
        query = " select CTPKB.MaThuoc,CTPKB.SoLuong from CHITIET_PKB CTPKB,PHIEUKHAMBENH PKB,DANHSACHKHAMBENH DSKB where DSKB.NgayKham=" + ngaykham + " and DSKB.MaBenhNhan=PKB.MaBenhNhan and PKB.MaPhieu=CTPKB.MaPhieu "
        DT_THUOC = DTP.Datatable_PHONGMACHTU(query)
        'lay ra tien thuoc ung voi ma thuoc roi cong don`
        For i As Integer = 0 To DT_THUOC.Rows.Count - 1
            Dim _mathuoc As Long = DT_THUOC.Rows(i)("MaThuoc")
            Dim _soluong As Long = DT_THUOC.Rows(i)("SoLuong")
            TongTienThuoc += DoanhThuTrongNgay_DAO.TIENTHUOC(_mathuoc, _soluong)

        Next
        _TongTien = TongTienKham + TongTienThuoc
        Dim ngaytruoc As Date
        Dim ngay As Integer
        Dim thang As Integer
        Dim nam As Integer
        ngay = ngaykham.Day
        thang = ngaykham.Month
        nam = ngaykham.Year
        Dim str As String
        str = thang.ToString() + "/" + ngay.ToString() + "/" + nam.ToString()
        ngaytruoc = Convert.ToDateTime(str)
        Dim doanhthungaytruoc As Long
        doanhthungaytruoc = DoanhThuTrongNgay_DAO.DOANHTHUNGAYTRUOC(ngaytruoc)






        'ket qua
        Dim kq As Integer
        Dim DTTN_DTO As New DoanhThuTrongNgayDTO()
        Try
            DTTN_DTO.Thang = ngaykham
            DTTN_DTO.SoBenhNhan = SoBenhNhanTrongNgay
            DTTN_DTO.DoanhThu = _TongTien
            Dim a As Double = Double.Parse(_TongTien)
            Dim b As Double = Double.Parse(doanhthungaytruoc)
            DTTN_DTO.TyLe = a / b
        Catch ex As Exception

        End Try
        kq = DoanhThuTrongNgay_DAO.INSERT(DTTN_DTO)
        Return kq

    End Function
End Class
